/**
 * Copyright [2019] [LiBo/Alex of copyright liboware@gmail.com ]
 * <p>
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * <p>
 * http://www.apache.org/licenses/LICENSE-2.0
 * <p>
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.hyts.algorithm.jianzhi;

import com.hyts.algorithm.Solution;
import com.sun.org.apache.bcel.internal.generic.PUSH;
import org.junit.Test;

import java.util.ArrayList;
import java.util.List;
import java.util.Stack;

/**
 * @project-name:coffice-toolbox
 * @package-name:com.hyts.algorithm.jianzhi
 * @author:LiBo/Alex
 * @create-date:2019-10-27 12:40
 * @copyright:libo-alex4java
 * @email:liboware@gmail.com
 * @description:
 */
public class TestLinkedNode implements Solution {


    class LinkedNode{

        Integer value;

        LinkedNode next;


        public LinkedNode(int value) {
            this.value = value;
        }

        public LinkedNode() {
        }

        public int getValue() {
            return value;
        }

        public void setValue(int value) {
            this.value = value;
        }

        public LinkedNode getNext() {
            return next;
        }

        public void setNext(LinkedNode next) {
            this.next = next;
        }

        @Override
        public String toString() {
            return "LinkedNode{" + "value=" + value + ", next=" + next + '}';
        }
    }


    @Test
    @Override
    public void solution1() {
        LinkedNode header = new LinkedNode(0);
        LinkedNode last = new LinkedNode();
        header.next = last;
        for(int i = 1 ; i < 9;i++){
            LinkedNode next = new LinkedNode(i);
            if(last.value == null){
                last = next;
                header.next = last;
            }else{
                last.next = next;
                last = next;
            }
        }
        System.out.println(header);
        List<Integer> data = new ArrayList<>();
        //LinkedNode[] linkedNodes = new LinkedNode[data.size()];
        for(int i = 0 ; i < data.size() ; i++){
            data.add( last.value);
            last = last.next;
        }
    }

    @Override
    public void solution2() {
        /**
         *    public class ListNode {
         *        int val;
         *        ListNode next = null;
         *
         *        ListNode(int val) {
         *            this.val = val;
         *        }
         *    }
         *
         *
                ArrayList<Integer> list = new ArrayList<>();
                ArrayList<Integer> list2 = new ArrayList<>();
                if(listNode == null){
                    return list;
                }
                while(listNode != null){
                    list.add(listNode.val);
                    listNode = listNode.next;
                }
                for(int i = list.size()-1;i>=0;i--){
                    list2.add(list.get(i));
                }
                return list2;
            }
         */

    }

    @Override
    public void solution3() {

        class solution{

            Stack<Integer> stack1 = new Stack<Integer>();
            Stack<Integer> stack2 = new Stack<Integer>();

            public void push(int node) {
                stack1.push(node);
            }
            public int pop() {
                if(stack2.isEmpty()){
                    while(!stack1.isEmpty()){
                        stack2.push(stack1.pop());
                    }
                }
                return stack2.pop();

            }
        }
        System.out.println(new solution().pop());
    }

    public static void main(String[] args){
        int[] elements = {1,2,3,4,5,6,7,8,9,0};
        stack stack1 = new stack(10);
        stack stack2 = new stack(10);
        for(int i =0 ;i<elements.length ; i++){
            stack1.push(elements[i]);
            stack2.push(stack1.pop());
            System.out.println(stack2.pop());
        }

    }

    static class stack {

        int pointer;

        Object[] elements;


        public stack(int element){
            pointer = element-1;
            elements = new Object[element];
        }

        public void push(Object obj){
            if(pointer >=1){
                elements[pointer--] = obj;
            }
        }

        public Object pop(){
            if(pointer < elements.length-1){
                return elements[++pointer];
            }
            return null;
        }
    }

}
